package com.linewow.xhyy.nihaonew.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.View;

import com.linewow.xhyy.nihaonew.R;
import com.linewow.xhyy.nihaonew.application.NiHaoApp;
import com.linewow.xhyy.nihaonew.base.BaseFragment;

/**
 * Created by LXR on 2016/8/23.
 */
public class MineFragment extends BaseFragment {
    private MineLoginFragment loginFragment;
    private MineMainFragment mainFragment;
    private FragmentManager fm;
    @Override
    public View initView() {
        View view=View.inflate(getActivity(),R.layout.fragment_mine,null);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        fm=getFragmentManager();
    }

    public void goneFragment(){
        FragmentTransaction ft=fm.beginTransaction();
        if(mainFragment!=null){
            ft.hide(mainFragment);
        }
        if(loginFragment!=null){
            ft.hide(loginFragment);
        }
        ft.commit();
    }
    public void showFragment(){
        goneFragment();
        FragmentTransaction ft=fm.beginTransaction();
        if(NiHaoApp.flag){
            if(mainFragment==null){
                mainFragment=new MineMainFragment();
                ft.add(R.id.mine_fragment,mainFragment);
            }else{
                ft.show(mainFragment);
            }
        }else{
            if(loginFragment==null){
                loginFragment=new MineLoginFragment();
                ft.add(R.id.mine_fragment,loginFragment);
            }else{
                ft.show(loginFragment);
            }
        }
        ft.commit();
    }

    @Override
    public void onResume() {
        super.onResume();
        showFragment();
    }
}
